package com.zhao.dota.processor;

import com.zhao.dota.common.processor.SteamProcessor;
import okhttp3.Request;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import org.springframework.stereotype.Component;

@Component
public class MatchProcessor extends SteamProcessor {

    private static final String URL = "https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/v1";

    public boolean isPractice(Long matchId) {
        Request request = super.buildGet(URL, new Param("match_id", matchId));
        try {
            String retJson = super.sendRequest(request);
            JSONObject result = new JSONObject(retJson).getJSONObject("result");
            return result.has("error") && String.valueOf(result.get("error")).contains("Practice");
        } catch (Exception e) {
            return true;
        }

    }

}
